export const createYears=()=>{
    const years=[]
    for(let i=1900;i<=2050;i++){
        years.push(i)
    }
    return years
}

export const createMonths=()=>{
    const months=[]
    for(let i=1;i<=12;i++){
        months.push(i)
    }
    return months
}

export const getCurrentDate=()=>{
    const date=new Date()
    
    return{
        year:date.getFullYear(),
        month:date.getMonth() + 1,
        day:date.getDate()
    }
}

export const initList = (year, month) => {
  const list = []

  // 1. 计算选中的年月的1号星期几
  const firstDate = new Date(year, month - 1, 1)
  let day = firstDate.getDay() // 0-6
  if (day === 0) {
    day = 7
  }

  // 2. 填充上个月
  // 2.1 计算上个月的最后一天
  const lastMonthLastDate = new Date(year, month - 1, 0)
  const an = lastMonthLastDate.getDate()
  // 2.2 上个月的总天数
  const n = day - 1
  const a0 = an - n + 1
  for (let i = a0; i <= an; i++) {
    list.push({ type: 'last', date: i })
  }

  // 3. 填充本月
  const monthLastDate = new Date(year, month, 0)
  // 3.1 本月的最后一天
  const bn = monthLastDate.getDate()
  for (let i = 1; i <= bn; i++) {
    list.push({ type: 'this', date: i })
  }

  // 4. 填充下个月
  const cn = 42 - n - bn
  for (let i = 1; i <= cn; i++) {
    list.push({ type: 'next', date: i })
  }

  return list
}